﻿var formatPriority = function (elCell, oRecord, oColumn, sData) {
    var showText;
    if (sData == "1") {
        showText = "<font color='red'>特急</font>";
    } else if (sData == "2") {
        showText = "<font color='green'>紧急</font>";
    } else {
        showText = "普通";
    }
    elCell.innerHTML = showText;
}

var formatShow = function (elCell, oRecord, oColumn, sData) {
    var WorkFlowInstanceId = oRecord.getData("WorkFlowInstanceId");
    var workflowId = oRecord.getData("WorkFlowId");
    var taskCaption = oRecord.getData("FlowCaption");
    var url = '"' + "../../Crm/BasePages/WorkflowMap.aspx?WorkFlowInstanceId=" + WorkFlowInstanceId + "&workflowId=" + workflowId + '"';
    var title;
    var taskTitle = "";
    if (taskCaption != undefined) {
        title = '"' + taskCaption + '流程图"';
    }
    else {
        title = '"' + taskTitle + '流程图"';
    }
    elCell.innerHTML = "<a href='javascript:transForForm(" + title + "," + url + ")'>流程图</a><br />";
}
var transForForm = function (title, url) {
    parent.addTabs(title, url);
    parent.NeedRefreshPage = this;
}
var formatCaption = function (elCell, oRecord, oColumn, sData) {
    var WorkTaskInstanceId = oRecord.getData("WorkTaskInstanceId");
    var OperatorInstanceId = oRecord.getData("OperatorInstanceId");
    var url = '"' + "../../Crm/BasePages/WorkTaskCtrlPage.aspx?WorkTaskInstanceId=" + WorkTaskInstanceId + "&OperatorInstanceId=" + OperatorInstanceId + '"';
    var title = '"' + sData + '"';
    var IsDisplay = oRecord.getData("IsDisplay");
    elCell.innerHTML = "";
    var sum = 0;
    var urls = "../../Images/new4.gif";
    if (IsDisplay != "") {
        var isDplay = "";
        var isnull = "  ";
        isDplay = IsDisplay.split(',');
        for (i = 0; i < isDplay.length; i++) {
            if (isDplay[i] = const_UserName) {
                sum = 1;
                break;
            }
        }
        if (sum == 0) {
            elCell.innerHTML = "<a href='javascript:transForForm(" + title + "," + url + ")'>" + sData + "&nbsp;&nbsp;&nbsp;<img src= " + urls + "></a><br />";
        }
        else {
            elCell.innerHTML = "<a href='javascript:transForForm(" + title + "," + url + ")'>" + sData + "</a><br />";
        }
    }
    else {
        elCell.innerHTML = "<a href='javascript:transForForm(" + title + "," + url + ")'>" + sData + "&nbsp;&nbsp;&nbsp;<img  src= " + urls + "></a><br />";
    }

}
var formatIsDisplay = function (elCell, oRecord, oColumn, sData) {
    var items = const_UserName;
    var sum = 0;
    if (sData != "") {
        var isDplay = "";
        isDplay = sData.split(',');
        for (i = 0; i < isDplay.length; i++) {
            if (isDplay[i] = const_UserName) {
                sum = 1;
                break;
            }
        }
        if (sum == 0) {
            var url = "../../Images/more02.jpg";
            elCell.innerHTML = "<a><img src= " + url + "></a><br />";
        }
    }
    else {
        var url = "../../Images/more02.jpg";
        elCell.innerHTML = "<a><img src= " + url + "></a><br />";
    }
}
//自动义双击方法
function CustomDbClick() { }

//自动义删除方法
var fnCustomDelete = function () {
    var list = this.mDataTable.getRecordSet()._records;
    var elist = [];
    dl = [];
    var dlClose = [];
    for (var i = 0; i < list.length; i++) {
        if (list[i]._oData["iSun_Selected"] == true) {
            elist.push(list[i]._oData[const_entityID]);
            dl.push(list[i]._sId); //获取行ID；
            dlClose.push(list[i]);
        }
    }
    var WorkFlowInstanceId = "";
    var WorkTaskInstanceId = "";
    for (var i = 0; i < dlClose.length - 1; i++) {
        if (i == 0) {
            WorkFlowInstanceId = dlClose[i]._oData["WorkFlowInstanceId"].toString() + ',';
            WorkTaskInstanceId = dlClose[i]._oData["WorkTaskInstanceId"].toString() + ',';
        }
        else {
            WorkFlowInstanceId += dlClose[i]._oData["WorkFlowInstanceId"].toString() + ',';
            WorkTaskInstanceId += dlClose[i]._oData["WorkTaskInstanceId"].toString() + ',';
        }
    }
    WorkFlowInstanceId += dlClose[dl.length - 1]._oData["WorkFlowInstanceId"].toString();
    WorkTaskInstanceId += dlClose[dl.length - 1]._oData["WorkTaskInstanceId"].toString();
    //    var WorkFlowInstanceId = list[0]._oData["WorkFlowInstanceId"];
    //    var WorkTaskInstanceId = list[0]._oData["WorkTaskInstanceId"];
    if (confirm("是否删除此流程?")) {
        var SaveUrl = "../../WorkFlow/Workformat.aspx?WorkFlowInstanceId=" + WorkFlowInstanceId + "&WorkTaskInstanceId=" + WorkTaskInstanceId + "&logType=2";
        YAHOO.util.Connect.asyncRequest('POST', SaveUrl, {
            success: function (res) {
                try {
                    var str = res.responseText.substring(0, 1);

                    if (str == "1") {
                        alert("流程删除成功");
                        var recordID = mDataTable.getSelectedRows()[0];
                        if (dl.length == 0) {
                            mDataTable.deleteRow(recordID);
                        }
                        else {
                            for (var i = 0; i < dl.length; i++) {
                                mDataTable.deleteRow(dl[i]);
                            }
                        }
                    }
                    else {
                        alert(res.responseText + "\n" + "流程删除失败!");
                    }
                }
                catch (e) {
                }
                finally {
                }
            },
            failure: function (error) {
                alert("数据错误：" + error.statusText);
            }
        }, null);
    }
}

//还原流程
var formatReturn = function (elCell, oRecord, oColumn, sData) {
    var WorkFlowInstanceId = oRecord.getData("WorkFlowInstanceId");
    var taskCaption = oRecord.getData("FlowCaption");
    var title = '"' + taskCaption + '还原流程"';
        elCell.innerHTML = "<a  href='javascript:void(0)' onclick='ColseClick(\"" + WorkFlowInstanceId + "\");'>还原流程</a>";
}
//还原流程
function ColseClick(WorkFlowInstanceId) {
    var list = this.mDataTable.getRecordSet()._records;
    var elist = [];
    dl = [];
    for (var i = 0; i < list.length; i++) {
        if (list[i]._oData["iSun_Selected"] == true) {
            elist.push(list[i]._oData[const_entityID]);
            dl.push(list[i]._sId); //获取行ID；
        }
    }
    if (confirm("是否还原此流程?")) {
        var SaveUrl = "../../WorkFlow/Workformat.aspx?WorkFlowInstanceId=" + WorkFlowInstanceId + "&logType=1";
        YAHOO.util.Connect.asyncRequest('POST', SaveUrl, {
            success: function (res) {
                try {
                    var str = res.responseText.substring(0, 1);

                    if (str == "1") {
                        alert("还原流程成功");
                        var recordID = mDataTable.getSelectedRows()[0];
                        if (dl.length == 0) {
                            mDataTable.deleteRow(recordID);
                        }
                        else {
                            for (var i = 0; i < dl.length; i++) {
                                mDataTable.deleteRow(dl[i]);
                            }
                        }
                    }
                    else {
                        alert(res.responseText + "\n" + "还原流程失败!");
                    }
                }
                catch (e) {
                }
                finally {
                }
            },
            failure: function (error) {
                alert("数据错误：" + error.statusText);
            }
        }, null);
    }
}